package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.List;
import java.io.PrintWriter;
/**
 * Created by neilbo on 8/01/2014.
 */
public class User {

    private String name;
    private String email;
    private String phone;
    private String libNumber;
    private String password;
    private PrintWriter printWriter;

    public User(String name, String email, String phone, String libNumber, String password) {

        this.name = name;
        this.email = email;
        this.phone = phone;
        this.libNumber = libNumber;
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public String getEmail() {
        return email;
    }

    public String getPhone() {
        return phone;
    }

    public String libNumber() {
        return libNumber;
    }

    public String password() {
        return password;
    }

    public String getMyInfo() {
        return (name + ", " + email + ", " + phone);
    }

    public String testLibNumPassword() {

        return libNumber + ", " + password;
    }

    public boolean matchesUserInput(String inputlibNumber, String inputPassword) {
        if(this.libNumber().equals(inputlibNumber))
        {
            if(this.password().equals(inputPassword))
            {
                return true;
            }
        }
        return false;
    }


    private List<User> getUserList() {
        List<User> userList = new ArrayList<User>();
        userList.add(new User ("Neil", "neil@thoughtworks.com", "0434374921", "555-5555", "password"));
        userList.add(new User ("Bruce", "bruce@teneriffe.com", "0434374922", "555-5556", "password"));
        userList.add(new User ("Alicia", "alicia@coronarycare.com", "0434374923", "555-5557", "password"));
        return userList;
    }

    public String loginUser(String inputLibNum, String inputPassword) {
        List<User> userList = getUserList();
        for(int i = 0; i < userList.size(); i++)
        {
            if(userList.get(i).matchesUserInput(inputLibNum, inputPassword))
            {
                return userList.get(i).getMyInfo();
            }
        }
        return null;
    }
}
